package edu.hrbu.systemadmin.code;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Collections;
import java.util.List;

/**
 * @author 徐登宇
 */
public class CodeGenerator {

    public static final String URL="jdbc:mysql://localhost:3306/ydl-ssm";
    public static final String USERNAME="root";
    public static final String PASSWORD="Xu08052002@";

    public static void main(String[] args) {
//        generate();

    }

    public static void generate() {

        FastAutoGenerator.create(URL,
                        USERNAME,
                        PASSWORD)
                .globalConfig(builder -> {
                    builder.author("徐登宇") // 设置作者
//                            .enableSwagger() // 开启 swagger 模式
//                            .fileOverride() // 覆盖已生成文件
                            .outputDir("E:\\Java\\codes\\ydl\\ydl-ssm\\system-admin\\src\\main\\java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("edu.hrbu") // 设置父包名
                            .moduleName("systemadmin") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapper.xml, "E:\\Java\\codes\\ydl\\ydl-ssm\\system-admin\\src\\main\\resources\\mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(List.of(
                                    "ydl_menu",
                                    "ydl_oper_log",
                                    "ydl_role",
                                    "ydl_role_menu",
                                    "ydl_user",
                                    "ydl_user_role")) // 设置需要生成的表名
                            .addTablePrefix("t_", "c_")
                            .entityBuilder().enableFileOverride().enableLombok().logicDeleteColumnName("del_flag").logicDeletePropertyName("delFlag")
                            .mapperBuilder().enableFileOverride()
                            .serviceBuilder().enableFileOverride()
                            .controllerBuilder().enableFileOverride().enableRestStyle(); // 设置过滤表前缀
                })
                .execute();

    }

}
